import Vue from "vue";
import Vuex from "vuex";
//封装自己的库
import Public from "../plugins/public.js";
import sdk from '../plugins/wxshare';
Vue.use(Vuex);
import createPersistedState from 'vuex-persistedstate'

import {
  getUserInfo
} from "../request/api";
export default new Vuex.Store({
  plugins: [createPersistedState()],
  state: {

    userInfo: {},

    //通知栏高度
    statusBarHeight: 0,
    //导航栏高度
    vanNavBar: 46,
    getUrl: "http://www.zwb12138.xyz",



    // 测试服上传
    //复制链接
    linkUrl: "http://wx-001.unionnetwork.com",
    //图片域名
    imgUrl: 'http://wx-001.unionnetwork.com/zk/',
    //用来 分享 域名
    shareUrl: "http://wx-001.unionnetwork.com",
    //接口请求地址
    baseUrl: 'http://wx-001.unionnetwork.com/',
  },
  //同步
  mutations: {


    //保存用户登录信息
    setUserInfo(state, userInfo) {

      state.userInfo = userInfo;
      //设置标题
      sdk.setTitle(userInfo.companyName);
    },
  },
  //异步
  actions: {


    async updateUserInfo(context) {
      let info = JSON.parse(sessionStorage.getItem("userWxData"));
      let obj = {
        account: sessionStorage.getItem("agentId"),
        weChatNo: "",
        name: info.nickname,
        image: info.headimgurl,
        openId: info.openid,
        sex: info.sex,
        city: info.city,
        province: info.province,
        agentId: sessionStorage.getItem("shareId") ||
          sessionStorage.getItem("agentIds"),
      };
      let res = await getUserInfo(obj);

      context.commit("setUserInfo", res.data);
    },
  },
  modules: {}
});